


package yf.mall.controller;
import com.yf.request.SearchParam;

import java.math.BigDecimal;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import yf.mall.entity.ShopEntity;
import yf.mall.service.ShopService;
import yf.mall.vo.ShopParamVo;
import yf.mall.service.ShopParamService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
            
/**
 * 店铺设置Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 21 16:25:07 CST 2020
 */
@RestController
@RequestMapping("/shop/param")
public class ShopParamController {
    @Autowired
    private ShopParamService shopParamService;
    @Autowired
    private ShopService shopService;

    /**
     * 列表店铺设置
     */
    @SysLog("查看店铺设置")
    @RequestMapping("/list")
    @RequiresPermissions("shop:param:list")
    public R list(@RequestBody SearchParam<ShopParamVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<ShopParamVo> list = shopParamService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    /**
 * 下载订单
 */
    @SysLog("下载订单")
    @RequestMapping("/down")
    @RequiresPermissions("shop:param:list")
    public void down(@RequestBody SearchParam<ShopParamVo> params, HttpServletResponse response) {
        List<ShopParamVo> list = shopParamService.findVo(params.getEntity());
            shopParamService.downLoad(response, list);
    }


    /**
     * 查看店铺设置
     */
    @SysLog("查看店铺设置")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("shop:param:info")
    public R info(@PathVariable("id") Long id) {
            ShopParamVo vo = shopParamService.getVo(id);
            ShopEntity shopEntity = shopService.get(vo.getShopParam().getShopId());
            if (shopEntity != null){
                vo.getShopParam().setShopName(shopEntity.getName());
            }
        return R.ok(vo);
    }

    /**
     * 保存店铺设置
     */
    @SysLog("保存店铺设置")
    @RequestMapping("/save")
    @RequiresPermissions("shop:param:save")
    public R save(@RequestBody ShopParamVo vo) {
            shopParamService.saveVo(vo);
        ShopEntity shopEntity = shopService.get(vo.getShopParam().getShopId());
        if (shopEntity != null){
            vo.getShopParam().setShopName(shopEntity.getName());
        }
        return R.ok(vo);
    }

    /**
     * 修改店铺设置
     */
    @SysLog("修改店铺设置")
    @RequestMapping("/update")
    @RequiresPermissions("shop:param:update")
    public R update(@RequestBody ShopParamVo vo) {
            shopParamService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除店铺设置
     */
    @SysLog("删除店铺设置")
    @RequestMapping("/delete")
    @RequiresPermissions("shop:param:delete")
    public R delete(Long[]ids) {
            shopParamService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有店铺设置
     */
    @SysLog("所有店铺设置")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<ShopParamVo> list = shopParamService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
                                                                            return R.ok(options);
    }





    /***********自定义开始***********/

    @RequestMapping("/updateMaterialPrice/{materialPrice}")
    public R updateMaterialPrice(@PathVariable("materialPrice") BigDecimal materialPrice){
        shopParamService.updateMaterialPrice(materialPrice);
        return R.ok();
    }
}
